package com.leetcode.dp;

/**
 * @author Dennis Li
 * @date 2020/7/21 9:45
 */
public class MinCostTickets_983 {

    public int mincostTickets(int[] days, int[] costs) {
        int len = days.length;
        if (len == 0) return 0;
        int[] dp = new int[days[len - 1] + 1];
        int j = 0;
        for (int i = days[0]; i <= days[len - 1]; i++) {
            if (i < days[j]) {
                dp[i] = dp[i - 1];
                continue;
            }
            if (i < 7)
                dp[i] = Math.min(dp[i - 1] + costs[0], costs[1]);
            else if (i < 30)
                dp[i] = Math.min(dp[i - 1] + costs[0], Math.min(dp[i - 7] + costs[1], costs[2]));
            else
                dp[i] = Math.min(dp[i - 1] + costs[0], Math.min(dp[i - 7] + costs[1], dp[i - 30] + costs[2]));
            j++;
        }
        return dp[days[len - 1]];
    }

}
